/**
 * 
 */
package com.cp16.tss.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author GiangHN
 * @version 1.0
 * @since 01/01/2014
 */
public class DateConvertUtil {

	// String format: yyyyMMdd
	public static Date convertStringyyyMMddToDate(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}

	// String format: yyyy/MM/dd
	public static Date convertStringSlashyyyMMddToDate(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}

	// String format: yyyy-MM-dd
	public static Date convertStringDashyyyMMddToDate(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}

	// String format: ddMMyyyy
	public static Date convertStringddMMyyyyToDate(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat("ddMMyyyy");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}

	// String format: dd-MMM-yyyy
	public static Date convertStringddMMMyyyyToDate(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}

	// String format: dd-MM-yyyy
	public static Date convertStringDashddMMyyyyToDate(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}
	
	// String format: dd/MM/yyyy
	public static Date convertStringSlashddMMyyyyToDate(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}


	// String Format: MMM dd, yyyy
	public static Date convertStringMMddyyyyToDate(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}

	// String Format: MMM d, yyyy
	public static Date convertStringMMdyyyyToDate(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}

	// String format: E, MMM dd yyyy
	public static Date convertStringEMMMddyyyyToDate(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat("E, MMM dd yyyy");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}

	// String format: EEEE, MMM dd, yyyy HH:mm:ss a
	public static Date convertStringToDateTime(String dateInToString) {
		SimpleDateFormat formatter = new SimpleDateFormat(
				"EEEE, MMM dd, yyyy HH:mm:ss a");
		Date dateResult = null;
		if (dateInToString == null || dateInToString == "") {
			return null;
		} else {
			try {
				dateResult = formatter.parse(dateInToString);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return dateResult;
	}

	// Date format: dd/MM/yyyy
	public static String convertDateToStringddMMyyyySlash(Date date) {
		if (date == null) {
			return "";
		} else {
			SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
			return formatter.format(date);
		}
	}

	// Date format: dd-MM-yyyy
	public static String convertDateToStringddMMyyyyDash(Date date) {
		if (date == null) {
			return "";
		} else {
			SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
			return formatter.format(date);
		}
	}

	// Date format: yyyyMMdd
	public static String convertDateToStringyyyyMMdd(Date date) {
		if (date == null) {
			return "";
		} else {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
			return formatter.format(date);
		}
	}

	// Date format: yyyy-MM-dd
	public static String convertDateToStringyyyyMMddDash(Date date) {
		if (date == null) {
			return "";
		} else {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			return formatter.format(date);
		}
	}

	// Date format: yyyy/MM/dd
	public static String convertDateToStringyyyyMMddSlash(Date date) {
		if (date == null) {
			return "";
		} else {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
			return formatter.format(date);
		}
	}
}
